package easy;

import java.util.ArrayList;
import java.util.List;

public class Solution_459 {

    private List<String> list = null;

    public boolean repeatedSubstringPattern(String s) {
        List<Character> characters = new ArrayList<>();
        char[] chars = s.toCharArray();
        int length = chars.length;
        int sameLength = 1;
        characters.add(chars[0]);
        for (int i = 1; i <= length/2; i++) {
            if (length % i != 0) {
                continue;
            }
            // begin是开始比较的位置，数组的下标；i是当前模板的长度
            int begin = i;
            while (true) {
                boolean same = true;
                for (int j = 0; j < i; j++) {
                    if (chars[begin+j] == chars[j]) {
                        continue;
                    }
                    same = false;
                    break;
                }
                if (same) {
                    if ((begin + i) == length) {
                        return true;
                    } else {
                        begin += i;
                    }
                } else {
                    break;
                }
            }
        }
        return false;
    }

    public static void main(String[] args) throws InterruptedException {
        Solution_459 model = new Solution_459();
//        System.out.println(model.repeatedSubstringPattern("aabaaba"));
    }

    private void replace() {
        List<String> list1 = new ArrayList<>();
        long millis = System.currentTimeMillis();
        list1.add("zhoujuqi" + millis);
        list1.add("chenyu" + millis);
        list = list1;
    }

    private void print() {
        if (list != null) {
            System.out.println(String.join(",", list));
        }
    }

    /*
    private <T, R> R remoteRpc(T t, RemoteRpc<T, R> handler) {
        ResponseBaseVo<R> responseBaseVo = handler.apply(t);
        Assert.notNull(responseBaseVo, RemoteExceptionCode.DARWIN_API_NETWORK_ERROR);
        Assert.isTrue(responseBaseVo.isSuccess(), RemoteExceptionCode.DARWIN_API_ERROR,
            "运营城市查询接口", JsonUtil.toJSON(responseBaseVo));
        log.info("CoverStoreClient.batchQueryGeneralStoreCoverSaleStores success req:{}, res:{}",
            JsonUtil.toJSON(t), JsonUtil.toJSON(responseBaseVo));
        return responseBaseVo.getData();
    }

    @FunctionalInterface
    public interface RemoteRpc<T, R> {
        ResponseBaseVo<R> apply(T t);
    }
    */
}
